package com.javacode2018.lesson001.demo15;

/**
 * @Author: hongsir
 * @Date: 2024/10/11 - 10 - 11 - 9:58
 * @Description: com.javacode2018.lesson001.demo15
 * @Version: 1.0
 */
public class ServiceProxy implements  IService{
    //目标对象，被代理的对象
    private IService target;

    public ServiceProxy(IService target) {
        this.target = target;
    }

    @Override
    public void m1() {
        long startTime = System.nanoTime();
        this.target.m1();
        long endTime = System.nanoTime();
        System.out.println(this.target.getClass() + ".m1()方法耗时（纳秒）：" + (endTime - startTime));
    }

    @Override
    public void m2() {
        long startTime = System.nanoTime();
        this.target.m2();
        long endTime = System.nanoTime();
        System.out.println(this.target.getClass() + ".m2()方法耗时（纳秒）：" + (endTime - startTime));
    }

    @Override
    public void m3() {
        long startTime = System.nanoTime();
        this.target.m3();
        long endTime = System.nanoTime();
        System.out.println(this.target.getClass() + ".m3()方法耗时（纳秒）：" + (endTime - startTime));
    }
}
